package com.controller;

import com.entity.view.WebsocketView;
import com.service.YishiService;
import com.utils.R;
import com.utils.SpringBeanContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/liaotian")
public class ZaixianzixunController {


    @GetMapping("/onlineYishi")
    public R getUsernameList() {
        Set<String> allSids = WebSocketServer.onlineSessionClientMap.keySet();
        List<String> usernameList = new ArrayList<>(); // 实例化一个 ArrayList
// 遍历sid值
        for (String sid1 : allSids) {
            usernameList.add(sid1); // 向列表中添加元素
        }

        YishiService yishiService = SpringBeanContext.getContext().getBean(YishiService.class);
        List<WebsocketView> list = yishiService.selectUsernameByTable(usernameList);
        list = list.stream().filter(item -> item.getSource_table().equals("yishi")).collect(Collectors.toList());
        System.out.println("getUsernameList-----"+ list);
        return R.ok().put("data", list);
    }

}
